class Solution
{
public:
    int reachNumber(int target)
    {
        target = abs(target);
        int numMoves = 0;
        int total = 0;
        while (total < target)
        {
            ++numMoves;
            total += numMoves;
        }
        if (total > target && ((total - target) & 1))
        {
            ++numMoves;
            if (!(numMoves & 1))
            {
                ++numMoves;
            }
        }
        return numMoves;
    }
};